package com.crx.springbootinit.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.crx.springbootinit.annotation.AuthCheck;
import com.crx.springbootinit.annotation.LogApiAnno;
import com.crx.springbootinit.common.BaseResponse;
import com.crx.springbootinit.common.ResultUtils;
import com.crx.springbootinit.model.dto.logApi.LogApiPageDTO;
import com.crx.springbootinit.model.dto.logLogin.LogLoginPageDTO;
import com.crx.springbootinit.model.dto.page.PageVO;
import com.crx.springbootinit.model.entity.LogApi;
import com.crx.springbootinit.model.entity.LogLogin;
import com.crx.springbootinit.model.vo.logApi.LogApiPageVO;
import com.crx.springbootinit.model.vo.logLogin.LogLoginPageVO;
import com.crx.springbootinit.service.ILogLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 谢杭延
 * @Date 2024-11-01 12:58
 */
@RestController
@RequestMapping("/admin/logLogin")
@RequiredArgsConstructor
@Api(tags = "后台登录日志模块接口")
public class LogLoginAdminController {
    private final ILogLoginService logLoginService;

    @DeleteMapping("/delete/{ids}")
    @ApiOperation("删除登录日志")
    @LogApiAnno(title = "登录日志模块", businessType = "DELETE")
    @AuthCheck
    public BaseResponse<Void> deleteLogLogin(@ApiParam("登录日志id列表") @PathVariable List<String> ids){
        logLoginService.removeByIds(ids);
        return BaseResponse.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询登录日志列表")
    @AuthCheck
    public BaseResponse<PageVO<LogLoginPageVO>> queryLogLoginPage(LogLoginPageDTO logLoginPageDTO){
        PageVO<LogLoginPageVO> pageVO = logLoginService.queryLogLoginPage(logLoginPageDTO);
        return BaseResponse.success(pageVO);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询登录日志详情")
    @AuthCheck
    public BaseResponse<LogLoginPageVO> queryLogLoginById(@ApiParam("接口日志id") @PathVariable String id){
        LogLogin logLogin = logLoginService.getById(id);
        LogLoginPageVO logLoginPageVO = BeanUtil.copyProperties(logLogin, LogLoginPageVO.class);
        return BaseResponse.success(logLoginPageVO);
    }
}
